package com.ruoyi.kiku.service.impl;

import java.util.Collections;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.OssUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.kiku.mapper.KikuNewsImagesMapper;
import com.ruoyi.kiku.domain.KikuNewsImages;
import com.ruoyi.kiku.service.IKikuNewsImagesService;

/**
 * 小鞠新闻图片Service业务层处理
 *
 * @author TT
 * @date 2025-09-03
 */
@Service
public class KikuNewsImagesServiceImpl implements IKikuNewsImagesService
{
    @Autowired
    private KikuNewsImagesMapper kikuNewsImagesMapper;

    /**
     * 查询小鞠新闻图片
     *
     * @param id 小鞠新闻图片主键
     * @return 小鞠新闻图片
     */
    @Override
    public KikuNewsImages selectKikuNewsImagesById(Long id)
    {
        return kikuNewsImagesMapper.selectKikuNewsImagesById(id);
    }
    /**
     * 根据新闻id查询新闻图片
     *
     * @param newsId 新闻id
     * @return 新闻图片
     */
    @Override
    public List<KikuNewsImages> selectKikuNewsImagesByNewsId(Long newsId) {
        return kikuNewsImagesMapper.selectKikuNewsImagesByNewsId( newsId);
    }

    /**
     * 查询小鞠新闻图片列表
     *
     * @param kikuNewsImages 小鞠新闻图片
     * @return 小鞠新闻图片
     */
    @Override
    public List<KikuNewsImages> selectKikuNewsImagesList(KikuNewsImages kikuNewsImages)
    {
        return kikuNewsImagesMapper.selectKikuNewsImagesList(kikuNewsImages);
    }

    /**
     * 新增小鞠新闻图片
     *
     * @param kikuNewsImages 小鞠新闻图片
     * @return 结果
     */
    @Override
    public int insertKikuNewsImages(KikuNewsImages kikuNewsImages)
    {
        kikuNewsImages.setCreateTime(DateUtils.getNowDate());
        return kikuNewsImagesMapper.insertKikuNewsImages(kikuNewsImages);
    }

    /**
     * 修改小鞠新闻图片
     *
     * @param kikuNewsImages 小鞠新闻图片
     * @return 结果
     */
    @Override
    public int updateKikuNewsImages(KikuNewsImages kikuNewsImages)
    {
        kikuNewsImages.setUpdateTime(DateUtils.getNowDate());
        return kikuNewsImagesMapper.updateKikuNewsImages(kikuNewsImages);
    }

    /**
     * 批量删除小鞠新闻图片
     *
     * @param ids 需要删除的小鞠新闻图片主键
     * @return 结果
     */
    @Override
    public int deleteKikuNewsImagesByIds(Long[] ids)
    {
        for (int i = 0; i < ids.length; i++) {
            String url = kikuNewsImagesMapper.selectKikuNewsImagesById(ids[i]).getUrl();
            if (!url.isEmpty()){
                OssUtils.delete( url);
            }
        }
        return kikuNewsImagesMapper.deleteKikuNewsImagesByIds(ids);
    }

    /**
     * 删除小鞠新闻图片信息
     *
     * @param id 小鞠新闻图片主键
     * @return 结果
     */
    @Override
    public int deleteKikuNewsImagesById(Long id)
    {
        String url = kikuNewsImagesMapper.selectKikuNewsImagesById(id).getUrl();
        if (!url.isEmpty()){
            OssUtils.delete( url);
        }
        return kikuNewsImagesMapper.deleteKikuNewsImagesById(id);
    }
}
